package com.atguigu.lease.web.admin.custom.config.converter;
import com.atguigu.lease.model.enums.ItemType;
import org.springframework.core.convert.converter.Converter;
import org.springframework.stereotype.Component;


//只能转换一种枚举类型
@Component
public class StringToItemTypeConverter implements Converter<String,ItemType> {


    @Override
    public ItemType convert(String code) {
        for (ItemType value : ItemType.values()) {
            if (value.getCode().equals(Integer.valueOf(code))){
                return value;
            }
        }

        throw new IllegalArgumentException("code非法");
    }
}
